/**
 * Created by jiachneyu on 2018/3/22.
 */
const messagehandle = require('../model/message');
const JPush = require("../node_modules/jpush-async/index").JPushAsync;

const client = JPush.buildClient('ae25f554d429ecdf7eb8a018', '359fd33e6cfd3227a6a5be73')

//easy push


let sendMessage = async (ctx,next)=>{
    let msg = ctx.request.body;
    await messagehandle('send',msg,ctx).then(a=>{
        client.push().setPlatform(JPush.ALL)
            .setAudience(JPush.ALL)
            .setNotification('您有新的短信', JPush.ios('您有新的短信', 'happy', 5))
            .send()
            .then(function(result) {
                console.log(result)
            }).catch(function(err) {
            console.log(err)
        })
        ctx.response.body = a;
    })
}

let getMessage = async (ctx,next)=>{
    console.log(1231231231)
    await messagehandle('get','', ctx).then(a => {
        ctx.response.body = a;
    })
}




module.exports = [
    {
        method: "post",
        path: "/sendMessage",
        handle: sendMessage
    },{
        method: "post",
        path: "/getMessage",
        handle: getMessage
    }
]